<template>
	<view class="ljapp signpage">
		<view class="content">
			<view class="card" :class="item.status" v-for="(item,index) in group.list" :key="index">
				<view class="con u-flex">
					<image class="avatar" :src="$base.cdn(item.doctor_img)" mode="aspectFill"></image>
					<view class="u-flex-fill u-flex u-flex-items-stretch">
						<view class="info u-flex-fill">
							<view class="u-flex u-flex-items-end">
								<view>{{item.doctor_info?item.doctor_info.name||'--':'--'}}</view>
							</view>
							<!-- <view class="sn">订单号：{{item.order_code}}</view> -->
							<view class="sn u-line-1">
								擅长：{{item.doctor_info?item.doctor_info.be_good_at_synopsis||'--':'--'}}
							</view>
							<view class="time">日期：{{$u.timeFormat(item.createtime,'yyyy/mm/dd hh:MM')}}</view>
						</view>
						<view class="u-flex u-flex-wrap u-flex-content-between" style="width: 116rpx;min-width: 116rpx;">
							<view class="status" style="width: 100%;text-align: right;padding-right: 10rpx;">{{item.typename}}</view>
							<view class="btn-fillet"
								v-if="item.pay_status==2&&item.status=='normal'"
								@click.stop="openPayPop(item)">去支付</view>
						</view>
					</view>
				</view>
				<view class="foot u-flex u-flex-between">
					<view>签约医生服务</view>
					<view class="price" v-if="item.sign_package_info">
						￥{{parseFloat((parseFloat(item.sign_package_info.money)/parseInt(item.sign_package_num)).toFixed(2))}}元/{{item.sign_package_type=='month'?'月':(item.sign_package_type=='week'?'周':'天')}}
					</view>
				</view>
			</view>

			<lj-empty v-if="group.loaded&&group.list.length<=0">暂无订单</lj-empty>
			<view v-else>
				<u-loadmore
					:status="loading?'loading':(group.loaded?'nomore':'loadmore')"
					fontSize="28rpx"
					color="#d9d9d9"
					nomoreText="已加载全部"
					marginTop="30rpx"
					marginBottom="0"
					@loadmore="getList"
				></u-loadmore>
			</view>
		</view>

		<u-popup :show="show" mode="bottom">
			<view class="popup-pay-mode">
				<view class="popup-head">
					请选择支付方式
					<image class="close" src="/static/lj/drug/icon_close.png" mode="aspectFill" @click="show=false"></image>
				</view>
				<view class="popup-content">
					<!-- <view class="item u-flex u-flex-between u-flex-y-center">
						<view class="u-flex u-flex-y-center">
							<image class="icon" src="/static/lj/drug/icon_alipay.png" mode="aspectFill"></image>
							<view>支付宝</view>
						</view>
						<image class="ricon" src="/static/lj/drug/hook.png" mode="aspectFill"></image>
					</view> -->
					<view class="item u-flex u-flex-between u-flex-y-center">
						<view class="u-flex u-flex-y-center">
							<image class="icon" src="/static/lj/drug/icon_wechat.png" mode="aspectFill"></image>
							<view>微信</view>
						</view>
						<image class="ricon" src="/static/lj/drug/hook.png" mode="aspectFill"></image>
					</view>

					<view class="btn-capsule" @click="Onpaywait">确定支付</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group:{
					page: 1,
					limit: 10,
					list: [],
					loaded: false
				},
				loading: false,

				show: false,
				curItem: null,
			}
		},
		onLoad() {},
		onShow(){
			this.init()
		},
		methods: {
			init(){
				this.group.page = 1
				this.group.list = []
				this.group.loaded = false
				this.loading = false

				this.getList();
			},
			getList(){
				var that = this,group = that.group;
				if(that.loading || group.loaded) return;

				that.loading = true

				this.$Http({
					url: 'listConsultationSignOrder',
					data: {
						page: group.page,
						limit: group.limit,
					},
					type:'POST',
				}).then(res=>{
					if(res.code == 1){
						var list = res.data.data;
						group.loaded = list.length < group.limit;
						group.page ++;

						list.forEach(item => {
							if (item.pay_status == 2) {
								if (item.status == 'normal') {
									item.typename = '待支付'
								}
								if (item.status == 'cancel') {
									item.typename = '已取消'
								}
								item.status_is = false
							}
							if (item.pay_status == 1) {
								item.status_is = true
								if (item.status == 'normal') {
									item.typename = '待接诊'
								}
								if (item.status == 'refund') {
									item.typename = '已退款'
									item.status_is = false
								}
								if (item.status == 'refuse_patient') {
									item.typename = '拒绝接诊'
								}
								if (item.status == 'patient') {
									item.typename = '服务中'
								}
								if (item.status == 'end') {
									item.typename = '已失效'
								}
								if (item.status == 'comment') {
									item.typename = '已评价'
								}
							}
						})

						group.list = group.list.concat(list);
					}

					that.loading = false
				}).catch(()=>{
					that.loading = false
				});
			},
			onReachBottom(){
				this.getList()
			},

			openPayPop(item){
				this.curItem = item
				this.show = true
			},
			//去往等待页面
			Onpaywait() {
				let that = this

				if(!this.curItem || !this.curItem.order_code){
					return this.$u.toast('参数错误')
				}

				this.$Http({
					url: 'payConsultationSignOrder',
					type:'POST',
					data: {
						order_code: this.curItem.order_code
					},
					show: true,
				}).then(res => {
					if (res.code = 1) {
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.pacKage,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: function(res1) {
								console.log('Onpaywait requestPayment',res1)
							},
							fail: function(err) {
								console.log('Onpaywait requestPayment fail',err)
							}
						});
					}
				})

			}
		}
	}
</script>

<style lang="less">
	@import '@/pagesD/style.less';

	.btn-fillet{
		width: 116rpx;
		min-width: 116rpx;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 24rpx;
	}
</style>
